Imports cmplib01


Public Class frmEditDeployedChitIcons
    Inherits System.Windows.Forms.Form

    Private ptrUnit As UnitType


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents picOwner As System.Windows.Forms.PictureBox
    Friend WithEvents btnOk As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents picEnemy As System.Windows.Forms.PictureBox
    Friend WithEvents picFriendly As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.picOwner = New System.Windows.Forms.PictureBox
        Me.btnOk = New System.Windows.Forms.Button
        Me.picEnemy = New System.Windows.Forms.PictureBox
        Me.picFriendly = New System.Windows.Forms.PictureBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'picOwner
        '
        Me.picOwner.BackColor = System.Drawing.Color.Black
        Me.picOwner.Location = New System.Drawing.Point(16, 48)
        Me.picOwner.Name = "picOwner"
        Me.picOwner.Size = New System.Drawing.Size(33, 33)
        Me.picOwner.TabIndex = 0
        Me.picOwner.TabStop = False
        '
        'btnOk
        '
        Me.btnOk.Location = New System.Drawing.Point(112, 112)
        Me.btnOk.Name = "btnOk"
        Me.btnOk.TabIndex = 3
        Me.btnOk.Text = "OK"
        '
        'picEnemy
        '
        Me.picEnemy.BackColor = System.Drawing.Color.Black
        Me.picEnemy.Location = New System.Drawing.Point(80, 48)
        Me.picEnemy.Name = "picEnemy"
        Me.picEnemy.Size = New System.Drawing.Size(33, 33)
        Me.picEnemy.TabIndex = 4
        Me.picEnemy.TabStop = False
        '
        'picFriendly
        '
        Me.picFriendly.BackColor = System.Drawing.Color.Black
        Me.picFriendly.Location = New System.Drawing.Point(144, 48)
        Me.picFriendly.Name = "picFriendly"
        Me.picFriendly.Size = New System.Drawing.Size(33, 33)
        Me.picFriendly.TabIndex = 5
        Me.picFriendly.TabStop = False
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.Label1.Location = New System.Drawing.Point(8, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(38, 16)
        Me.Label1.TabIndex = 6
        Me.Label1.Text = "Owner"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.Label2.Location = New System.Drawing.Point(80, 24)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(39, 16)
        Me.Label2.TabIndex = 7
        Me.Label2.Text = "Enemy"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.Label3.Location = New System.Drawing.Point(144, 24)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(45, 16)
        Me.Label3.TabIndex = 8
        Me.Label3.Text = "Friendly"
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.Label4.Location = New System.Drawing.Point(8, 88)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(118, 16)
        Me.Label4.TabIndex = 9
        Me.Label4.Text = "Click on an icon to edit"
        '
        'frmEditDeployedChitIcons
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(194, 144)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.picFriendly)
        Me.Controls.Add(Me.picEnemy)
        Me.Controls.Add(Me.btnOk)
        Me.Controls.Add(Me.picOwner)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "frmEditDeployedChitIcons"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Edit Icons"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Property Unit() As UnitType
        Get
            Return ptrUnit
        End Get
        Set(ByVal Value As UnitType)
            ptrUnit = Value
            PopulateImages()
        End Set
    End Property

    Private Sub PopulateImages()
        Try
            ' popuates the images currently in the unit
            picOwner.Image = ptrUnit.Icon(cmplib01.IconImageIndex_cgd.Owner)
            picEnemy.Image = ptrUnit.Icon(cmplib01.IconImageIndex_cgd.Enemy)
            picFriendly.Image = ptrUnit.Icon(cmplib01.IconImageIndex_cgd.SameFaction)

        Catch ex As Exception

        End Try

    End Sub

    Private Sub SaveImages()
        ' saves the images back in to the unit
        Try
            ptrUnit.Icon(cmplib01.IconImageIndex_cgd.Owner) = picOwner.Image
            ptrUnit.Icon(cmplib01.IconImageIndex_cgd.Enemy) = picEnemy.Image
            ptrUnit.Icon(cmplib01.IconImageIndex_cgd.SameFaction) = picFriendly.Image
        Catch ex As Exception

        End Try
    End Sub

    Private Sub SetNewImage(ByRef pic As PictureBox)
        ' sets the new imagin into the picturebox

        Try
            Dim fil As New OpenFileDialog
            fil.Filter = "Pictures | *.bmp; *.jpg"
            fil.ShowDialog()

            pic.Image = Image.FromFile(fil.FileName)
            fil.Dispose()

        Catch ex As Exception
            HandleException("grr", ex)
        End Try
    End Sub

    Private Sub picOwner_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picOwner.Click, picEnemy.Click, picFriendly.Click
        SetNewImage(sender)

    End Sub

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        SaveImages()
        Me.Hide()
    End Sub
End Class
